<!-- 模块说明 -->
<template>
  <div>
    <Form
      :options="options"
      :options2="options2"
      :getId="getId"
      :submitList="submitList"
      :gettId="gettId"
      @onSumbit="onSumbit"
    >
    </Form>
  </div>
</template>

<script setup lang="ts">
import { addQuestionList, editQuestionList } from "../../api/question";
import { ref, onMounted } from "vue";
import Form from "../../components/form/trueFalse.vue";
import { getGradeList, getSubjectList } from "../../api/index";
import { useRoute, useRouter } from "vue-router";
import { useStore } from "vuex";
const options = ref<any[]>([]);
const options2 = ref<any[]>([]);
const route = useRoute();
const router = useRouter();
const store = useStore();
const submitList = ref(
  route.query.id
    ? store.state.topic.profile
    : {
        id: 0,
        questionType: 0,
        subjectId: 0,
        score: 0,
        correct: "",
        topicResource1: "",
        topicResource2: "",
        difficult: 0,
        shortTitle: "",
        item: [],
      }
);
const getGrade = async () => {
  let res = await getGradeList();
  options.value = res.data;
  // console.log(res);
};
const getId = async (item: any) => {
  console.log(item.id);
  let res = await getSubjectList({ level: item.id });
  options2.value = res.data;
};
const count = ref<number>(0);
const gettId = (item: any) => {
  count.value = item.xueid;
};
const onSumbit = async (form: any) => {
  // console.log(form);
  submitList.value = {
    id: Date.now(),
    questionType: 3,
    subjectId: count,
    score: form.score,
    topicResource1: form.topicResource1,
    topicResource2: form.topicResource2,
    item: [form.topicResource1, form.topicResource2],
    correct: form.correct,
    difficult: form.difficult,
    shortTitle: form.shortTitle,
  };
  console.log(submitList.value, "cao");
  if (route.query.id !== undefined) {
    await editQuestionList(route.query.id, submitList.value);
  } else {
    await addQuestionList(submitList.value);
  }
  router.push("/topic");
};
onMounted(() => {
  getGrade();
});
</script>
<style lang="scss" scoped></style>
